/* SVN FILE: $Id: message.js 50 2008-11-03 22:26:02Z killergeorge@gmail.com $ */
/**
 * To quote Dave Cardwell: 
 * Built on the shoulders of giants:
 *   * John Resig      - http://jquery.com/
 *
 * Jamal Message component:  Javascript MVC Assembly Layout <http://jamal-mvc.com/>
 * Copyright (c)    2007, Georg Leciejewski
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright        Copyright (c) 2007, Timo Derstappen
 * @link            
 * @package          jamal
 * @subpackage       jamal.message
 * @since            Jamal v 0.4
 * @version          $Revision: 50 $
 * @modifiedby       $LastChangedBy: killergeorge@gmail.com $
 * @lastmodified     $Date: 2008-11-03 22:26:02 +0000 (Mon, 03 Nov 2008) $
 * @license          http://www.opensource.org/licenses/mit-license.php The MIT License
 */

/**
 * Jamal message component
 *
 * This component serves as a "Message Div Handler"
 * you can use it to show messages in a div container with the id #msg
 * <div id="msg"></div>
 * The div must be present in you html code 
 * and the component must be included in the app_controller:
 * 		$j.extend($j.fn.c.prototype, {
 *  		components: ['message'],
 *  
 * In your controller you can then use the message like this:
 * 
 *     jamal.message('Don´t you click on me ... dude', 'error');
 * 
 * As you see you can pass an additional parameter into that good old message component.
 * 
 * 'error' -> css class added to the div
 * 
 * You can also set a boolean flag as the third option 
 * This will append the message to the div instead of cleaning it
 *  jamal.message('Your click was so hard ... babe', 'success_msg', true);
 *
 * @public
 * @name jamal
 * @cat message
 */
jamal.fn.extend({
    /* Constructor */
	/**
	 * Start the jamal message handling
	 * 
     * @example jamal.message("Elvis is alive", 'error');
     * @desc no default startup options so far
	 * @public
	 * @name message
	 * @type Object
	 * @cat message
	 */
     message: function(){	 	
         
     }
}); 

jamal.fn.extend(jamal.fn.message, {
	
	/**
	 * Flag for server-side message check
	 *
	 * @public
	 * @property
	 * @name jamal.message.active
	 * @type Boolean
	 * @cat message
	 */
    msg_container: '#msg',

    
	/**
     * Show a message div
	 *
	 * @example jamal.message.show();
	 *
	 * @public
	 * @name jamal.message.show
	 * @type Function
	 * @cat message
	 * @param String msg - the message to show
	 * @param String type - the mssagetype which adds a different class to the message div
	 * @param Boolean append_msg - if set to true the msg is append instead of cleaning the div first
	 */
    show: function(msg, type, append_msg) {
       
	   if(append_msg !== true)
	   {// do that cleanup
	   		jamal.message.close();
	   }
	  
	  	$(this.msg_container).addClass(type)
							 .append(msg) 				//append message
							 .show()					//show container
							 .click(function () {		//closer click		
								jamal.message.close();	//i love this chaining
							});
    },
	
	/**
	 * removes the class, cleans, closes and unbinds the click event from the message div. 
	 * @name jamal.message.close
	 * @type Function
	 * @cat message
	 */
	close: function () {
		
		$(this.msg_container).removeClass()
							.empty()
							.hide()
							.unbind('click');
	}   

});

